<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box {
            display: grid;
            grid-template-columns: 1fr 1fr;
            margin-bottom: 10px;
            grid-row-gap: 5px;
            align-items: center;
        }

        .btn {
            display: grid;
            align-items: center;
            grid-template-columns: 1fr;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="">半径</label><input type="number" id="radius" value="200" onchange="setRadius()">

            <label for="">报警样式</label><select name="mode" id="mode1" onchange="setMode()">
                <option value="cylinder" selected>柱状警告</option>
                <option value="circle">圆形警告</option>
            </select>
        </div>
        <div class="btn">
            <button onclick="paintESAlarm()">重新创建</button>
            <button onclick="flyTo()">飞行定位</button>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            domid: document.getElementById("app"),
        });
        viewer.ionAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyZmQzMDI1OC1kMWYyLTQ1ZjEtYTJmNS0yMjY1ZDcxZjEyOTkiLCJpZCI6NjQ3MTgsImlhdCI6MTYyOTQzNDM5M30.m8vkzG05QiAfe6JQ0XPK8z_6KuUVMf_CoSY-YlMnAIg"
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                // 视口创建完成，飞到初始视角位置
                objm.activeViewer.flyIn([
                    109.87431251005586,
                    19.479225135155424,
                    1126.7502711784025
                ], [
                    358.83685654805055,
                    -31.800142399569175,
                    0.0036869980307010666
                ], 3)
            }
        })

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        /** ---------------------------------报警------------------------------------**/

        const { ESAlarm } = XE2['esobjs-xe2-plugin-main']
        const sceneObject = objm.createSceneObject(ESAlarm)
        sceneObject.position = [109.87399458575753, 19.495019102999088, 0]
        sceneObject.rotation = [90, 0, 0]
        // 报警半径大小
        sceneObject.radius = 200

        /**
         * 报警模式
         * "cylinder" 柱状警告
         * "circle" 圆形警告
         * 
        */
        sceneObject.mode = "cylinder"

        // 重新创建报警
        function paintESAlarm() {
            sceneObject.editing = false
            sceneObject.position = [0, 0, 0]
            sceneObject.editing = true
        }

        // 设置报警半径大小
        function setRadius() {
            sceneObject.radius = Number(document.getElementById("radius").value)
        }

        // 设置报警模式
        function setMode() {
            sceneObject.mode = document.getElementById("mode1").value
        }

        // 飞行定位
        function flyTo() {
            sceneObject.flyTo()
        }
    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>